<template>
	<view class="main">
		<view class="list" v-for="(item,index) in list" :key="index">
			<view class="item">
				<text class="Number"> {{index+1}} &nbsp; </text> 姓名：{{item.username}}
			</view>
			<view class="item">
				手机号码：{{item.mobile}}
			</view>
			<view class="item">
				购买状态：{{item.vip == 1?"已购买":'未购买'}}
			</view>
			<view class="item">
				注册时间：{{item.createtime | time}}
			</view>
			<view class="item" v-if="item.vip == 1">
				过期时间：{{item.vip_over_time | time}}
			</view>
			<view class="item" v-if="item.address">
				地址：{{item.address}}
			</view>
		</view>
		<u-empty v-if="list.length==0" text="暂无数据" mode="list"></u-empty>
	</view>
</template>

<script>
	import {
		myCustomer
	} from "@/api/index";
	export default {
		data() {
			return {
				page: 1,
				size: 10,
				list: []
			};
		},
		filters: {
			time(time) {
				let date = new Date(time * 1000);
				let year = date.getFullYear();
				let month = ('0' + (date.getMonth() + 1)).slice(-2); // 月份从0开始，需要加1，并且补零
				let day = ('0' + date.getDate()).slice(-2);
				let hours = ('0' + date.getHours()).slice(-2);
				let minutes = ('0' + date.getMinutes()).slice(-2);
				let seconds = ('0' + date.getSeconds()).slice(-2);

				// 拼接成最终的时间字符串
				return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
			}
		},
		mounted() {
			this.getMyCustomer()
		},
		methods: {
			getMyCustomer() {
				let params = {
					page: this.page,
					page_size: 10,
				}
				myCustomer(params).then(res => {
					this.list = this.list.concat(res.data.list)
					uni.stopPullDownRefresh();
				})
			},
			enablePullDownRefresh() {
				this.page++
				this.getMyCustomer()
			}
		},
	}
</script>

<style lang="scss">
	.main {
		background-color: #f6f6f6;
		padding-top: 20rpx;

		.list {
			margin-bottom: 20rpx;
			padding: 0 20rpx;

			.item {
				border-bottom: 1px solid #f2f2f2;
				padding: 20rpx 26rpx;
				font-size: 28rpx;
				color: #656565;
				background-color: #fff;

				.Number {
					color: #E52F68;
					font-weight: 600;
					font-size: 32rpx;
					margin-right: 5rpx;
				}
			}

			.item:last-child {
				border: none
			}
		}
	}
</style>